<template>
  <el-card style="margin: 150px auto; background-color: #fff; width: 450px; height: 270px; padding: 20px; border-radius: 10px">
    <el-form label-width="120px" size="small" :model="form" :rules="rules" ref="pass">
      <el-form-item label="社团名字:" prop="campusName">
        <el-input v-model="form.campusName" autocomplete="off" ></el-input>
      </el-form-item>
      <el-form-item label="社团规模:" prop="campusScale">
        <el-input v-model="form.campusScale" autocomplete="off" ></el-input>
      </el-form-item>
      <el-form-item label="社团简介:" prop="campusInfo">
        <el-input type="textarea" v-model="form.campusInfo" autocomplete="off" ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="save">确 定</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>
export default {
  name: "Password",
  data() {
    return {
      form: {},
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
      rules: {
        campusName: [
          {required: true, message: '请输入社团名称', trigger: 'blur'},
          {min: 2, max: 6, message: '长度在 2 到 6 个字符', trigger: 'blur'}
        ],
        campusScale: [
          {required: true, message: '请输入社团规模(人)', trigger: 'blur'},
          {min: 1, max: 3, message: '长度在 1 到 3 个字符', trigger: 'blur'}
        ],
        campusInfo: [
          {required: true, message: '请输入社团简介', trigger: 'blur'},
          {min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur'}
        ],
      }
    }
  },
  created() {
    this.form.userId = this.user.id,
    this.form.masterName = this.user.nickname
  },
  methods: {
    save() {
      this.$refs['pass'].validate((valid) => {
        if(valid){
            this.request.post("/campus/create", this.form).then(res => {
            if (res.code === '200') {
              this.$message.success("创建成功,已提交审核，请耐心等待")
            } else {
              this.$message.error(res.msg)
            }
          })
        }
      })
    },
    
  }
}
</script>

<style>
.avatar-uploader {
  text-align: center;
  padding-bottom: 10px;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 138px;
  height: 138px;
  line-height: 138px;
  text-align: center;
}
.avatar {
  width: 138px;
  height: 138px;
  display: block;
}
</style>
